import React from 'react'
import { createBrowserRouter, RouteObject, Navigate } from 'react-router-dom'
import Login from '@/views/login'
import Error403 from '@/views/error/403'
import Error404 from '@/views/error/404'
import Layout from '@/layout'
import AuthLoader from './AuthLoader'
import { lazyLoad } from './LazyLoad'

/**
 * 动态
 */
export const dynamicRoutes: RouteObject[] = [
  {
    path: '/',
    element: <Navigate to='/dashboard' />
  },
  {
    element: <Layout />,
    id: 'root',
    loader: AuthLoader,
    children: [
      {
        path: '/dashboard',
        element: lazyLoad(React.lazy(() => import('@/views/dashboard')))
      },
      {
        path: '/userList',
        element: lazyLoad(React.lazy(() => import('@/views/system/user')))
      },
      {
        path: '/deptList',
        element: lazyLoad(React.lazy(() => import('@/views/system/dept')))
      },
      {
        path: '/menuList',
        element: lazyLoad(React.lazy(() => import('@/views/system/menu')))
      },
      {
        path: '/roleList',
        element: lazyLoad(React.lazy(() => import('@/views/system/roles')))
      }
    ]
  }
]

export const constantsRoutes = [
  { path: '/login', element: <Login /> },
  { path: '*', element: <Navigate to='/404' /> },
  { path: '/404', element: <Error404 /> },
  { path: '/403', element: <Error403 /> }
]

const router = createBrowserRouter([...dynamicRoutes, ...constantsRoutes])

export default router
